package backTrack;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class Class491 {

    List<List<Integer>> result = new ArrayList<>();
    LinkedList<Integer> path = new LinkedList<Integer>();
    boolean[]  flag;

    public List<List<Integer>> findSubsequences(int[] nums) {
        flag=new boolean[nums.length];
        Arrays.fill(flag,false);
        backTracking(nums,flag,0);
        return result;
    }
    public void backTracking(int[] nums, boolean[] flag,int start) {
        if (path.size()>1){
            result.add(new ArrayList<>(path));
        }
//        if (start>=nums.length){
//            return;
//        }

//  CKG TODO 2023/4/22: 为什么是201呢?
        int[] used = new int[201];
        for (int i = start; i < nums.length ; i++) {
//            if (i>0&&nums[i]==nums[i-1]&&!flag[i-1]){
//                continue;
//            }
            if (!path.isEmpty()&&nums[i]<path.get(path.size()-1)||
                    (used[nums[i]+100]==1))
                continue;
            used[nums[i]+100]=1;
//            flag[i]=true;
            path.add(nums[i] );
            backTracking(nums, flag,i+1);
            path.removeLast();
//            flag[i]=false;
        }

    }

    public static void main(String[] args) {
        Class491 class491 = new Class491();
        int[] arr={4,6,7,7};
        System.out.println(class491.findSubsequences(arr).toString());
    }

}
